#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        vector<int> hash(k, 0);
        int cur = 0, ret = 0;
        hash[0] = 1;
        for (auto e : nums)
        {
            cur = ((cur + e) % k + k) % k;
            if (hash[cur]) ret += hash[cur];
            hash[cur]++;
        }
        return ret;
    }
};